//
// Created by wk on 2024/1/2.
//

#include "EncryptTypeH265.h"

int EncryptTypeH265::isH265Encrypt(char *buf, int size) {
    if (size >= 8) {
        off32_u *p = (off32_u *) buf;
        if ((p[0] ^ p[1]) == SH265_FLAG) {
            return 1;
        }
    }
    return -1;
}

bool EncryptTypeH265::isEncryptType(FILE *inputFile) {
    fseek(inputFile, 0, SEEK_SET);
    memset(preLoadBuffer, 0, sizeof(preLoadBuffer));

    int ret = fread(preLoadBuffer, 1, sizeof(preLoadBuffer), inputFile);
    if (ret != sizeof(preLoadBuffer)) {
        return false;
    }

    if (isH265Encrypt(preLoadBuffer, 16) < 0) {
        return false;
    }
    return true;
}

EncryptTypeH265::EncryptTypeH265() {
    mEncryptType = EncryptType::EncryptType_H265;
}

EncryptTypeH265::~EncryptTypeH265() {

}
